package org.test;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.cloudgarden.resource.SWTResourceManager;

public class Temp {
	private static Display display;

	public static void main(String[] args) {
	        display = new Display();
	        Shell shell = new Shell(display, SWT.SHELL_TRIM);
	        
	        shell.setLayout(new FillLayout());

	        // create the sc
	        final ScrolledComposite sc = new ScrolledComposite(shell,SWT.V_SCROLL);
	        sc.setExpandHorizontal(true);
	        sc.setExpandVertical(true);
	        sc.getVerticalBar().setIncrement(5);

	        // create the composite on the sc
	        final Composite endpointComp = new Composite(sc, SWT.NONE);
	        //GridData suGridData = new GridData(GridData.FILL_HORIZONTAL);
	        //endpointComp.setLayoutData(suGridData);
	        //endpointComp.setLayout(new GridLayout(1, true));
	        //RowData data = new RowData();
	        
	       // endpointComp.setLayoutData(data);
	        RowLayout layout = new RowLayout(SWT.VERTICAL);
	        layout.fill = true;
	        layout.center = true;
	        layout.justify = true;
	        layout.pack = true;
	        endpointComp.setLayout(layout);
	        //shell.setSize(234, 406);
	        //add button to the endpointComp
	        addCompToEndpointComp(endpointComp);
	        
	        sc.addControlListener(new ControlAdapter() {
	            public void controlResized(ControlEvent e) {

	                Point p = endpointComp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	                sc.setMinSize(p.x, p.y + 10);
	                endpointComp.layout();
	            }
	        });
	        sc.setContent(endpointComp);        
	        //shell.setControl(sc);


	        shell.setVisible(true);
	        while (!shell.isDisposed()) {
	            if (!display.readAndDispatch())
	                display.sleep();
	        }
	        display.dispose();
	    }

	    private static void addCompToEndpointComp(Composite endpointComp) {
	        for (int i = 0; i < 5; i++) {
	        					
	        	CLabel cLabel1 = new CLabel(endpointComp, SWT.LEFT | SWT.EMBEDDED);
				RowData cLabel1LData = new RowData();
				cLabel1LData.width = 150;
				cLabel1LData.height = 42;
				cLabel1.setLayoutData(cLabel1LData);
				cLabel1.setText("cLabel2");
				cLabel1.setBackground(SWTResourceManager.getColor(1, 172, 254));
				File file = new File("src\\org\\test\\images.jpg");
				System.out.println(file.exists());
				Image image = new Image(display,file.getAbsolutePath());
				cLabel1.setImage(image);
				
				//cLabel1.setImage(image);
	            /*Button button = new Button(endpointComp, SWT.FLAT);
	            
	            button.setText("ForTestBtn");
	            //button.setLayoutData(new GridData());
	            RowData data = new RowData();
	            data.width = 200;
	            //data.height = 50;
	            button.setLayoutData(data);*/
	        }

	    }
}
